/*
 * Author: http://www.redwolf-soft.com
 * All Rights Reserved
 * 
 * 2013.12
 *   
 * */

package com.redwolfsoft.libshoppingserver.brand;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


import com.redwolfsoft.libshoppingserver.shoppingcenter.ShoppingCenterInfo;


public class RecommendCategoryInfo {
	public final static String TAG = "RecommendCategoryInfo";
	
	public String id = null;
	public String name = null;
	List<ShoppingCenterInfo> shoppingCenterList = null;
	
	public RecommendCategoryInfo(String id, String name,
			List<ShoppingCenterInfo> shoppingCenterList) {
		this.id = id;
		this.name = name;
		this.shoppingCenterList = shoppingCenterList;
	}
	

	public RecommendCategoryInfo(JSONObject obj)
	{
		if(obj==null)
		{
			//Log.w(TAG, "JSONObject is null");
			return;
		}
		//try {		
			id = obj.getString("id");
			name = obj.getString("name");			
			
			shoppingCenterList = new ArrayList<ShoppingCenterInfo>();
			JSONArray array1 = obj.getJSONArray("shoppingCenterList");
			for(int i=0;i<array1.size();i++)
			{			
				JSONObject info = array1.getJSONObject(i);
				//Log.d(TAG,info.toString());
				shoppingCenterList.add(new ShoppingCenterInfo(info));
			}
			
			
		//} catch (JSONException e) {
			// TODO Auto-generated catch block
		//	e.printStackTrace();
		//}
	}
	
	public JSONObject toJsonObject()
	{
		JSONObject obj = new JSONObject();
		//JSONObject obj2 = new JSONObject();
		//try {
			obj.put("id", id);
			obj.put("name", name);
			JSONArray array1 = new JSONArray();
			for(int i=0;i<shoppingCenterList.size();i++)
			{
				array1.add(i,shoppingCenterList.get(i).toJsonObject());
			}
			obj.put("shoppingCenterList", array1);
			
			//obj2.put(TAG, obj);
		//} catch (JSONException e) {
			// TODO Auto-generated catch block
		//	e.printStackTrace();
		//	return null;
		//}
		return obj;
		
	}
}
